package top.ntboy.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import top.ntboy.demo.domain.Student;
import top.ntboy.demo.service.StudentService;

import java.util.List;

@Controller
@RequestMapping("/stu")
//@RestController  =  @Controller +  @ResponseBody
@Slf4j
public class HelloController {


    private StudentService studentService;

    @Autowired
    public void setStudentService(StudentService studentService) {
        this.studentService = studentService;
    }

    @RequestMapping("/index")
    public String hello(ModelMap modelMap) {
        List<Student> allStudent = studentService.getAllStudent();
        modelMap.put("students", allStudent);
        log.info("学生列表{}", allStudent);
        return "hello";
    }
}
